package com.pureut.storage.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.storage.dto.IncomingMaterialPrintingDetailDto;
import com.pureut.storage.service.IncomingMaterialPrintingDetailService;
import com.pureut.storage.vo.DeleteDetailVo;
import com.pureut.storage.vo.IncomingMaterialPrintingVo;
import com.pureut.storage.vo.IncomingMaterialSubcontractPrintingVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 采购打印明细控制层
 * Author:C
 * Date:2023/01/16 15:25
 * @DESC
 */
@RestController
@RequestMapping("/incoming-material-printing-detail")
public class IncomingMaterialPrintingDetailController extends BaseController {

    @Resource
    IncomingMaterialPrintingDetailService incomingMaterialPrintingDetailService;

    /**
     * 采购打印明细列表
     */
    @GetMapping("/list")
    public TableDataInfo getList(long id) {
        startPage();
        //查询采购打印明细列表
        List<IncomingMaterialPrintingDetailDto> list  = incomingMaterialPrintingDetailService.getDetailList(id);
        return getDataTable(list);
    }

    /**
     * 委外打印明细列表
     */
    @GetMapping("/subcontractList")
    public TableDataInfo getSubcontractList(long id) {
        startPage();
        //查询委外打印明细列表
        List<IncomingMaterialPrintingDetailDto> list  = incomingMaterialPrintingDetailService.getSubcontractList(id);
        return getDataTable(list);
    }

    /**
     * 采购打印
     */
    @RequiresPermissions("warehouse:incomingPrint:cgPrint:print")
    @PostMapping("/print")
    @Log(title = "采购打印", businessType = BusinessType.INSERT)
    public AjaxResult print(@RequestBody IncomingMaterialPrintingVo incomingMaterialPrintingVo) {
        return AjaxResult.success(incomingMaterialPrintingDetailService.getPrint(incomingMaterialPrintingVo));
    }

    /**
     * 委外打印
     */
    @RequiresPermissions("warehouse:incomingPrint:cgPrint:print")
    @PostMapping("/subcontractPrint")
    @Log(title = "委外打印", businessType = BusinessType.INSERT)
    public AjaxResult subcontractPrint(@RequestBody IncomingMaterialSubcontractPrintingVo incomingMaterialSubcontractPrintingVo) {
        return AjaxResult.success(incomingMaterialPrintingDetailService.subcontractPrint(incomingMaterialSubcontractPrintingVo));
    }

    /**
     * 来料打印页面对应的号码全部删除，上表的打印状态更新为“已完成”(fegin调用)
     */
    @PostMapping("/deleteDetail")
    @Log(title = "来料打印页面对应的号码全部删除，上表的打印状态更新为“已完成”", businessType = BusinessType.DELETE)
    public AjaxResult deleteDetail(@RequestBody DeleteDetailVo deleteDetailVo) {
        return toAjax(incomingMaterialPrintingDetailService.deleteDetail(deleteDetailVo));
    }

    /**
     * 删除来料打印页面数据（fegin调用）
     */
    @PostMapping("/deleteData")
    @Log(title = "删除来料打印页面数据（fegin调用）", businessType = BusinessType.DELETE)
    public AjaxResult deleteData(@RequestBody DeleteDetailVo deleteDetailVo) {
        return toAjax(incomingMaterialPrintingDetailService.deleteData(deleteDetailVo));
    }

}
